<?php include("/includes/header.php") ?>
<?php include("/includes/sidebar.php") ?>

<div class="header">
	<span>
		<a href="data_seleksi.php">
			<i class="fa fa-th-list"></i> Data Seleksi
		</a>
	</span>
	<span>
		<a href="data_seleksi-form.php?act=new">
			<i class="fa fa-plus"></i> Tambah Data
		</a>
	</span>
</div>
<div class="breadcumb">
	<ul>
		<li>
			<a href="/">
				<i class="fa fa-home"></i> Beranda
			</a>
		</li>
	</ul>
	<div class="clear"></div>
</div>

<div class="content row-fluid">
	<div class="span12 table-placer" data-table="data_seleksi" data-prim-field="id">
		<div class="alert alert-info">Tabel Data Seleksi</div>
		<table class="table table-striped" id="data_table">
			<thead>
				<tr>
					<th>
						<i class="fa fa-square-o opa3 check-all" data-toggle="tooltip" title="tekan untuk memilih seluruh data"></i>
						<input type="checkbox" class="check-real-all hide">
					</th>
					<th>No</th>
					<th>Nama</th>
					<th>Kode</th>
					<th>Keterangan</th>
					<th>User</th>
					<th></th>
				</tr>
			</thead>
			<tbody>
				<?php
					$sql_data_seleksi = "SELECT * FROM data_seleksi";
					$query_data_seleksi = mysql_query($sql_data_seleksi);
					$i = 1;
					while ($result_data_seleksi = mysql_fetch_array($query_data_seleksi)) {
				?>
					<tr>
						<td>
							<i class="fa fa-square-o opa3 check" data-toggle="tooltip" title="tekan untuk menandai data"></i>
							<input type="checkbox" class="check-real hide" value="<?php echo $result_data_seleksi[id]; ?>">
						</td>
						<td><?php echo $i; ?></td>
						<td><?php echo $result_data_seleksi[nama]; ?></td>
						<td><?php echo $result_data_seleksi[kode]; ?></td>
						<td><?php echo $result_data_seleksi[keterangan]; ?></td>
						<td>
							<?php
								 if ($result_data_seleksi[iduser] == 0) {
									echo "Tuhan Yang Maha Esa";
								 } else {
								 	$sql_user = "SELECT * FROM user WHERE id = '$result_data_seleksi[iduser]'";
								 	$query_user = mysql_query($sql_user);
								 	$result_user = mysql_fetch_array($query_user);
								 	echo $result_user['nama'];
								 }
							?>
						</td>
						<td>
							<a href="/data_seleksi-form.php?act=edit&id=<?php echo $result_data_seleksi[id]; ?>">
								<i class="fa fa-pencil" data-toggle="tooltip" title="Edit <?php echo $result_data_seleksi['nama'] ?>"></i>
							</a>
						</td>
					</tr>
				<?php
						$i++;
					}
				?>
			</tbody>
		</table>
		<ul class="breadcrumb well">
			<button class="btn btn-danger btn-hapus disabled" data-toggle="tooltip" title="Hapus data yang telah ditandai">
				<i class="fa fa-trash-o"></i> Hapus
			</button>
		</ul>
	</div>
</div>

<div class="footer">
</div>

<?php include("/includes/footer.php") ?>

<script type="text/javascript">
	$(document).ready(function() {
		$('#data_table').dataTable( {
			"sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
			"sPaginationType": "bootstrap",
			"aoColumns": [
				{ "sClass": "center", "bSearchable": false, "bSortable": false },
				{ "sClass": "center", "bSearchable": false, "bSortable": false},
				{ "sClass": "left", "bSearchable": true, "bSortable": true },
				{ "sClass": "left", "bSearchable": true, "bSortable": true },
				{ "sClass": "left", "bSearchable": true, "bSortable": true },
				{ "sClass": "left", "bSearchable": true, "bSortable": true },
				{ "sClass": "left", "bSearchable": false, "bSortable": false }
			],
			"oLanguage": {
				"sLengthMenu": "_MENU_ data per halaman"
			}
		})

		$('.btn-simpan').click(function(event) {
			if (validate_form()) {
				if ($('.act').val() == "edit") {
					act_form = "edit";
				} else {
					act_form = "new";
				}

				var formDataSeleksi = {
					nama: $('.nama').val(),
					kode: $('.kode').val(),
					keterangan: $('.keterangan').val(),
					act: 1,
					act_form: act_form
				}

				$.ajax({
					url: '/action/act_data_seleksi.php',
					type: 'POST',
					data: formDataSeleksi,
					cache: false,
	        success: function(data){
	        	if (data == "sukses") {
		        	alert("Data berhasil ditambahkan");
		        	window.location = "data_seleksi.php";
	        	} else {
	        		alert(data);
	        	}
	        }
				})
			};
		});
	});
</script>